<?php

class ProfileDocumentService extends BaseService
{

    private $employeeDao;

    /**
     * Set EmployeeData Access Object
     * @param EmployeeDao $employeeDao
     * @return void
     */
    public function setEmployeeDao(EmployeeDao $employeeDao)
    {
        $this->employeeDao = $employeeDao;
    }

    /**
     * Get the Employee Data Access Object
     * @return EmployeeDao
     */
    public function getEmployeeDao()
    {
        if (is_null($this->employeeDao)) {
            $this->employeeDao = new EmployeeDao();
        }
        return $this->employeeDao;
    }

    public function getEmployee($empNumber)
    {
        return $this->getEmployeeDao()->getEmployee($empNumber);
    }

    public function getEmployeeProfileDocuments($empNumber)
    {
        return $this->getEmployeeDao()->getEmployeeProfileDocuments($empNumber);
    }

    public function getNextEmployeeAttachmentId($empNumber)
    {
        $q = Doctrine_Query::create()
            ->select('MAX(a.attach_id)')
            ->from('EmployeeAttachment a')
            ->where('a.emp_number = ?', $empNumber);
        $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);

        if (count($result) != 1) {
            throw new PIMServiceException('MAX(a.attach_id) failed.');
        }

        return (is_null($result[0]['MAX']) ? 1 : $result[0]['MAX'] + 1);
    }
}